import request from 'umi-request';

export async function getCredentialList(params,status) {
  return request('/hr-ssc/api/api-admin/credential/getCredentialList', {
    method: 'post',
    data:{
      status,
      ...params,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function checkCredential(data) {
  return request('/hr-ssc/api/api-admin/credential/checkCredential', {
    method: 'post',
    data:data,
  }).then(res => res);
}

export async function deleteCredential(id){
  return request('/hr-ssc/api/api-admin/credential/deleteCredential', {
    method: 'delete',
    params:{id},
  }).then(res => res);
}

export async function getHangList(params,status) {
  return request('/hr-ssc/api/api-admin/credential/getHangList', {
    method: 'post',
    data:{
      ...params,
      status: status ? status : params.audit ? [params.audit] : null,
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function checkCredentialHang(data) {
  return request('/hr-ssc/api/api-admin/credential/checkCredentialHang', {
    method: 'post',
    data:data,
  }).then(res => res);
}

export async function unVaildCredentialHang(data) {
  return request('/hr-ssc/api/api-admin/credential/unVaildCredentialHang', {
    method: 'post',
    data:data,
  }).then(res => res);
}

export async function getCredentialItemList(data) {
  return request('/hr-ssc/api/api-admin/credential/getCredentialItemList', {
    method: 'post',
    data:data,
  }).then(res => {
    if (res.flag){
      return res.data;
    }
    return null
  });
}

export async function saveOrUpdateCredentialItem(data) {
  return request('/hr-ssc/api/api-admin/credential/saveOrUpdateCredentialItem', {
    method: 'post',
    data:data,
  }).then(res => res);
}

export async function saveOrUpdateCredential(data) {
  return request('/hr-ssc/api/api-admin/credential/saveOrUpdateCredential', {
    method: 'post',
    data:data,
  }).then(res => res);
}

export async function credentialBpm(hangId) {
  return request('/hr-ssc/api/api-admin/bpm/credentialBpm', {
    method: 'post',
    data: {hangId},
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}
